package org.example.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.dto.CropPageQueryDto;
import org.example.dto.CropSaveDto;
import org.example.result.PageResult;
import org.example.service.CropService;
import org.example.mapper.CropMapper;
import org.example.utils.SnowFlake;
import org.example.vo.CropVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author 19816
 * @description 针对表【t_crop】的数据库操作Service实现
 * @createDate 2024-05-26 19:41:53
 */
@Service
public class CropServiceImpl implements CropService {

    @Autowired
    private CropMapper cropMapper;

    public PageResult listAll(CropPageQueryDto cropPageQueryDto) {
        PageHelper.startPage(cropPageQueryDto.getPageNum(), cropPageQueryDto.getPageSize());
        Page<CropVo> page = cropMapper.listAll(cropPageQueryDto);
        return PageResult.builder()
                .recodes(page)
                .total(page.getTotal())
                .build();
    }

    /**
     * 农作物新增
     *
     * @param cropSaveDto
     */
    public void saveCrop(CropSaveDto cropSaveDto) {
        long id = new SnowFlake().nextId();
        cropSaveDto.setId("C" + id);
        cropMapper.saveCrop(cropSaveDto);
    }

    /**
     * 农作物删除
     *
     * @param id
     */
    public void delCrop(String id) {
        cropMapper.delCrop(id);
    }

}




